From arbi.informatik.uni-oldenburg.de!netcom.com!owner-pbmplus Fri Apr 22 11:31:44 1994
Return-Path: <netcom.com!owner-pbmplus@arbi.informatik.uni-oldenburg.de>
Received: by faramir.Informatik.Uni-Oldenburg.DE (Smail3.1.22.1)
	id <m0puHaI-0005Gqa>; Fri, 22 Apr 94 11:31 CES
Received: by arbi.informatik.uni-oldenburg.de (smail3.1.18 + xalias);
	Fri, 22 Apr 94 11:31 CES
Received: from localhost by mail.netcom.com (8.6.4/SMI-4.1/Netcom)
	id CAA17347; Fri, 22 Apr 1994 02:12:12 -0700
Received: from arbi.informatik.uni-oldenburg.de by mail.netcom.com (8.6.4/SMI-4.1/Netcom)
	id CAA17130; Fri, 22 Apr 1994 02:08:35 -0700
Received: by arbi.informatik.uni-oldenburg.de (smail3.1.18 + xalias);
	Fri, 22 Apr 94 05:13 CES
Received: by faramir.Informatik.Uni-Oldenburg.DE (Smail3.1.22.1)
	id <m0puBWS-0005GqC>; Fri, 22 Apr 94 05:03 CES
Message-Id: <m0puBWS-0005GqC@faramir.Informatik.Uni-Oldenburg.DE>
Subject: pcxtoppm diff - new & improved
To: pbmplus@netcom.com (PBMPlus Mailinglist)
Date: Fri, 22 Apr 94 5:03:13 CES
From: Ingo Wilken <Ingo.Wilken@arbi.informatik.uni-oldenburg.de>
X-Mailer: ELM [version 2.3 PL11]
Precedence: bulk
Status: RO

Hello again,

I just noticed that pcxtoppm does all its conversion in memory, and this
could be changed to row-by-row operation with minimal effort.  The conversion
now requires almost no memory, and it also got a bit faster.

So, here's the new diff - please delete the last one.  This diff has to be
applied to the pcxtoppm.c from the 01mar94 Netpbm distribution.

Regards,
Ingo

----------cut here----------
*** pcxtoppm.c.orig	Mon Oct 04 10:12:14 1993
--- pcxtoppm.c	Thu Apr 21 22:21:47 1994
***************
*** 15,25 ****
--- 15,31 ----
   * event will the author be liable for any lost revenue or profits or
   * other special, indirect and consequential damages.
   *
+  * Modified 20/Apr/94 by Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
+  *  - checks if 16-color-palette is completely black -> use standard palette
+  *  - "-stdpalette" option to enforce this
+  *  - row-by-row operation
   */
  
  #include        <stdio.h>
  #include        "ppm.h"
  
+ /*#define DEBUG*/
+ 
  #define PCX_MAGIC       0x0a            /* PCX magic number             */
  #define PCX_HDR_SIZE    128             /* size of PCX header           */
  #define PCX_256_COLORS  0x0c            /* magic number for 256 colors  */
***************
*** 26,32 ****
  
  #define	MAXCOLORS   	256
  #define	MAXPLANES	4
! #define	PCX_MAXVAL	255
  
  static void read_pcx_image ARGS(( FILE *fp, unsigned char *buf, int BytesPerLine, int Planes, int Height ));
  static void pcx_planes_to_pixels ARGS(( unsigned char *pixels, unsigned char *bitplanes, int bytesperline, int planes, int bitsperpixel ));
--- 32,38 ----
  
  #define MAXCOLORS       256
  #define MAXPLANES       4
! #define PCX_MAXVAL      (pixval)255
  
  static void read_pcx_image ARGS(( FILE *fp, unsigned char *buf, int BytesPerLine, int Planes, int Height ));
  static void pcx_planes_to_pixels ARGS(( unsigned char *pixels, unsigned char *bitplanes, int bytesperline, int planes, int bitsperpixel ));
***************
*** 34,39 ****
--- 40,49 ----
  static int GetByte ARGS(( FILE *fp ));
  static int GetWord ARGS(( FILE *fp ));
  
+ static unsigned char StdRed[]   = { 0, 255,   0,   0, 170, 170, 170, 170, 85,  85,  85,  85, 255, 255, 255, 255 };
+ static unsigned char StdGreen[] = { 0, 255, 170, 170,   0,   0, 170, 170, 85,  85, 255, 255,  85,  85, 255, 255 };
+ static unsigned char StdBlue[]  = { 0, 255,   0, 170,   0, 170,   0, 170, 85, 255,  85, 255,  85, 255,  85, 255 };
+ 
  int
  main(argc, argv)
      int         argc;
***************
*** 53,77 ****
      unsigned char	*pcximage;
      unsigned char	*pcxplanes;
      unsigned char	*pcxpixels;
!     pixel		**pixels;
  
- 
      ppm_init( &argc, argv );
  
!     switch (argc)
!     {
! 	 case 1:
  	     ifname	= "standard input";
  	     ifp	= stdin;
- 	     break;
- 	 case 2:
- 	     ifname	= argv[1];
- 	     ifp	= pm_openr(ifname);
- 	     break;
- 	 default:
- 	     pm_usage("[pcxfile]");
- 	     break;
      }
  
      /*
       * read the PCX header
--- 63,96 ----
      unsigned char       *pcximage;
      unsigned char       *pcxplanes;
      unsigned char       *pcxpixels;
!     pixel               *pixelrow;
!     int                 argn;
!     short               palette_ok = 0;
!     short               use_std_palette = 0;
!     char *usage = "[-stdpalette] [pcxfile]";
  
      ppm_init( &argc, argv );
  
!     argn = 1;
!     while( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' ) {
!         if( pm_keymatch(argv[argn], "-stdpalette", 2) ) {
!             use_std_palette = 1;
!         }
!         else
!             pm_usage(usage);
!         ++argn;
!     }
!     if( argn < argc ) {
!         ifname  = argv[1];
!         ifp     = pm_openr(argv[argn]);
!         ++argn;
!     }
!     else {
          ifname  = "standard input";
          ifp     = stdin;
      }
+     if( argn != argc )
+         pm_usage(usage);
  
      /*
       * read the PCX header
***************
*** 101,109 ****
       */
      for (i = 0; i < 16; i++)
      {
! 	 Red[i]	   = GetByte(ifp);
! 	 Green[i]  = GetByte(ifp);
! 	 Blue[i]   = GetByte(ifp);
      }
  
      (void) GetByte(ifp);		/* skip reserved byte	 */
--- 120,140 ----
       */
      for (i = 0; i < 16; i++)
      {
!          if( (Red[i]   = GetByte(ifp)) != 0 ) palette_ok = 1;
!          if( (Green[i] = GetByte(ifp)) != 0 ) palette_ok = 1;
!          if( (Blue[i]  = GetByte(ifp)) != 0 ) palette_ok = 1;
!     }
! 
!     /* check if palette is ok  - IUW */
!     if( !palette_ok || use_std_palette ) {
! #ifdef DEBUG
!         pm_message("using standard palette");
! #endif
!         for( i = 0; i < 16; i++ ) {
!             Red[i]   = StdRed[i];
!             Green[i] = StdGreen[i];
!             Blue[i]  = StdBlue[i];
!         }
      }
  
      (void) GetByte(ifp);                /* skip reserved byte    */
***************
*** 111,116 ****
--- 142,155 ----
      BytesPerLine= GetWord(ifp);         /* # of bytes per line   */
      (void) GetWord(ifp);                /* ignore palette info   */
  
+ #ifdef DEBUG
+     pm_message("Version: %d", Version);
+     pm_message("BitsPerPixel: %d", BitsPerPixel);
+     pm_message("Xmin: %d   Ymin: %d   Xmax: %d   Ymax: %d", Xmin, Ymin, Xmax, Ymax);
+     pm_message("Planes: %d    BytesPerLine: %d", Planes, BytesPerLine);
+ #endif
+ 
+ 
      /*
       * check that we can handle this image format
       */
***************
*** 156,167 ****
  	}
      }
  
-     pixels	= ppm_allocarray(Width, Height);
      pcxpixels	= (unsigned char *)pm_allocrow(Width+7, 1);
  
      /*
       * convert the image
       */
      for (y = 0; y < Height; y++)
      {
  	 pcxplanes = pcximage + (y * BytesPerLine * Planes);
--- 195,207 ----
          }
      }
  
      pcxpixels   = (unsigned char *)pm_allocrow(Width+7, 1);
+     pixelrow = ppm_allocrow(Width);
  
      /*
       * convert the image
       */
+     ppm_writeppminit(stdout, Width, Height, PCX_MAXVAL, 0);
      for (y = 0; y < Height; y++)
      {
           pcxplanes = pcximage + (y * BytesPerLine * Planes);
***************
*** 180,193 ****
  	 for (x = 0; x < Width; x++)
  	 {
  	     i = pcxpixels[x];
! 	     PPM_ASSIGN(pixels[y][x], Red[i], Green[i], Blue[i]);
  	 }
      }
  
      pm_close(ifp);
- 
-     ppm_writeppm(stdout, pixels, Width, Height, (pixval) 255, 0 );
- 
      pm_close(stdout);
  
      exit(0);
--- 220,231 ----
           for (x = 0; x < Width; x++)
           {
               i = pcxpixels[x];
!              PPM_ASSIGN(pixelrow[x], Red[i], Green[i], Blue[i]);
           }
+          ppm_writeppmrow(stdout, pixelrow, Width, PCX_MAXVAL, 0);
      }
  
      pm_close(ifp);
      pm_close(stdout);
  
      exit(0);
----------cut here----------


-- 
Ingo Wilken, CS Student, Univ.of Oldenburg, FRG | You mean I really did all of
wilken@uniol.uucp (..!uunet!unido!uniol!wilken) | dat stuff? Now dat explains
Ingo.Wilken@arbi.informatik.uni-oldenburg.de    | why my head hurts an' why I
wilken@uniol.zer   IRC:Nobody   OL:ingo@faramir | feel so bad!  -Snarf

